package com.yanh.product.controller;


import com.yanh.jcommon.utils.PageUtils;
import com.yanh.jcommon.utils.R;
import com.yanh.jcommon.valid.ValidGroup;
import com.yanh.product.entity.BrandEntity;
import com.yanh.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 *
 */
@Tag(name="品牌接口",description = "品牌接口")
@RestController
@RequestMapping("product/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @Operation(summary = "品牌列表",description = "品牌列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 品牌测试
     */
    @Operation(summary = "品牌测试",description = "品牌测试")
    @GetMapping("/test")
    public R test(){
        var page = brandService.list();
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @Operation(summary = "品牌信息",description = "品牌信息")
    @GetMapping ("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @Operation(summary = "保存品牌",description = "保存品牌")
    @PostMapping("/save")
    public R save(@Validated(value = ValidGroup.Crud.Create.class) @RequestBody BrandEntity brand){
        brandService.save(brand);
        return R.ok();
    }

    /**
     * 修改
     */
    @Operation(summary = "修改品牌",description = "修改品牌")
    @PostMapping("/update")
    public R update(@Validated(value = ValidGroup.Crud.Update.class) @RequestBody BrandEntity brand){
		brandService.updateDetail(brand);
        return R.ok();
    }

    /**
     * 修改状态
     */
    @PostMapping("/update/status")
    public R updateStatus( @RequestBody BrandEntity brand){
        brandService.updateById(brand);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));
        return R.ok();
    }
}
